/**
 * Created with JetBrains PhpStorm.
 * User: lunjiang
 * Date: 13-1-18
 * Time: 下午6:47
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function(){
    $(".date").datepicker({ dateFormat: "yy-mm-dd" });
    $(".detail").bind('click',function(){
        var obj= $(this);
        obj.parent().parent().children("td").css("border-top","1px solid #b9b9b9")
        obj.parent().parent().next().children("td").css("border-top","1px solid #b9b9b9");
        var bu_id = obj.attr("bu_id");
        var fid = obj.attr("fid");

        var type= 1;
        var start = $(".start").val();
        var end = $(".end").val();
        var className = "added"+ bu_id;//添加的列是className="added"加上事业部的id
        if(obj.hasClass("expended")){
            obj.removeClass("expended");
            $("."+ className).remove();
            obj.parent().parent().children("td").css("border-top","1px dotted #909090");
            obj.parent().parent().children("td:first").css("border-top","none");
            obj.parent().parent().next().children("td").css("border-top","1px dotted #909090");
            obj.parent().parent().next().children("td:first").css("border-top","1px solid white");
            return;
        }
        jQuery.ajax({
            async:true,
            url:url_dep_list,
            data:{type:type,bu_id:bu_id,start:start,end:end,fid:fid},
            type:'post',
            success:function (data) {
                var objdata = eval('(' + data + ')');
                if(objdata.errcode){//存在员工档案
                    /**
                     * 数据格式
                     * data
                     * data {status:1,data=[{city:'上海',dimissRate:'12%',voluntaryRate:10%,involuntaryRate:10%,belowLevel:10,aboveLevel:10,position1:1,position2:1,position3:1,
                     * position4:1,position5:1}]}
                     */
                    var strArray = [];
                    var arr = objdata.data;
                    for(var i in arr){
                        //alert(i);
                        var tempData = arr[i];
                        var cityName = tempData.city_name;
                        var fact_num = tempData.fact_num;
                        var plan_num = tempData.plan_num;
                        var p_num = tempData.p_num;
                        var m_num = tempData.m_num;
                        var job_time_1 = tempData.job_time_1;
                        var job_time_2 = tempData.job_time_2;
                        var job_time_3 = tempData.job_time_3;
                        var job_time_4 = tempData.job_time_4;
                        var job_time_5 = tempData.job_time_5;
                        var degree_1 = tempData.degree_1;
                        var degree_2 = tempData.degree_2;
                        var degree_3 = tempData.degree_3;
                        var url = tempData.url;

                        var str = '';
                        str  = str + '<tr class='+className+'><td class="indentTD">&nbsp;</td><td class="city">'+cityName+"</td>";
                        str = str + "<td>"+fact_num+'/'+plan_num+ "</td>";
                        str = str + '<td>'+p_num+'/'+m_num +"</td>";
                        str = str + '<td>'+job_time_1+ "</td>";
                        str = str + "<td>"+job_time_2+ "</td>";
                        str = str + "<td>"+job_time_3+ "</td>";
                        str = str + "<td>"+job_time_4+ "</td>";
                        str = str + "<td>"+job_time_5+ "</td>";
                        str = str + "<td>"+degree_1+ "</td>";
                        str = str + "<td>"+degree_2+ "</td>";
                        str = str + "<td>"+degree_3+ "</td>";
                        str = str + "<td>"+''+ "</td>";
                        strArray.push(str);
                    }
                    var str = strArray.join('');
                    $(str).insertAfter(obj.parent().parent());
                    obj.addClass("expended");
                }
            }
        });

    });

});